package com.ruoyi.web.controller.personnelMatters;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.compensationManagement.service.ICompensationSalarySettingService;
import com.ruoyi.personnelMatters.domain.*;
import com.ruoyi.personnelMatters.service.IPerScheduledTasksService;
import com.ruoyi.personnelMatters.service.IPersonScheduledService;
import com.ruoyi.system.service.ISysCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * 定时任务增查Controller
 *
 * @author zy
 * @date 2022-09-25
 */
@RestController
@RequestMapping("/personScheduled")
public class PersonScheduledController extends BaseController {
    @Autowired
    private IPersonScheduledService personScheduledService;

    @Autowired
    private ISysCommonService sysCommonService;

    @Autowired
    private ICompensationSalarySettingService compensationSalarySettingService;

    private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * 调整岗位
     *
     * @param positionChangeScanInfo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:insertPositionChangeScanInfo')")
    @Log(title = "【人员调整】调整岗位", businessType = BusinessType.INSERT)
    @PostMapping("/insertPositionChangeScanInfo")
    public AjaxResult insertPositionChangeScanInfo(@RequestBody PositionChangeScanInfo positionChangeScanInfo) {
        int result = personScheduledService.insertPositionChangeScanInfo(positionChangeScanInfo);
        if (result > 0) {
            return AjaxResult.success("【调整岗位成功】,生效时间为：" + formatter.format(positionChangeScanInfo.getPositionChangeEffectiveDate()));
        } else {
            return AjaxResult.error("【调整岗位失败】");
        }
    }

    /**
     * 查下拉岗位类型下拉列表
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:getPositionTypeDropDownOptions')")
    @GetMapping("/getPositionTypeDropDownOptions")
    public AjaxResult getPositionTypeDropDownOptions() {
        return AjaxResult.success(sysCommonService.selectPositionType());
    }

    /**
     * 输入用户id查岗位信息数据
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:getPositionByUserId')")
    @GetMapping(value = "/getPositionByUserId/{userId}")
    public AjaxResult getPositionByUserId(@PathVariable("userId") Long userId) {
        return AjaxResult.success(personScheduledService.getPositionByUserId(userId));
    }

    /**
     * 调整职务
     *
     * @param postChangeScanInfo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:insertPostChangeScanInfo')")
    @Log(title = "【人员调整】调整职务", businessType = BusinessType.INSERT)
    @PostMapping("/insertPostChangeScanInfo")
    public AjaxResult insertPostChangeScanInfo(@RequestBody PostChangeScanInfo postChangeScanInfo) {
        int result = personScheduledService.insertPostChangeScanInfo(postChangeScanInfo);
        if (result > 0) {
            return AjaxResult.success("【调整职务成功】,生效时间为：" + formatter.format(postChangeScanInfo.getPostChangeEffectiveDate()));
        } else {
            return AjaxResult.error("【调整职务失败】");
        }
    }

    /**
     * 输入用户id查职务信息数据
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:getPostByUserId')")
    @GetMapping(value = "/getPostByUserId/{userId}")
    public AjaxResult getPostByUserId(@PathVariable("userId") Long userId) {
        return AjaxResult.success(personScheduledService.getPostByUserId(userId));
    }


    /**
     * 查下拉职务类型下拉列表
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:getPostTypeDropDownOptions')")
    @GetMapping("/getPostTypeDropDownOptions")
    public AjaxResult getPostTypeDropDownOptions() {
        return AjaxResult.success(sysCommonService.selectPostType());
    }


    /**
     * 调整科室
     *
     * @param deptChangeScanInfo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:insertDeptChangeScanInfo')")
    @Log(title = "【人员调整】调整科室", businessType = BusinessType.INSERT)
    @PostMapping("/insertDeptChangeScanInfo")
    public AjaxResult insertDeptChangeScanInfo(@RequestBody DeptChangeScanInfo deptChangeScanInfo) {
        int result = personScheduledService.insertDeptChangeScanInfo(deptChangeScanInfo);
        if (result > 0) {
            return AjaxResult.success("【调整科室成功】,生效时间为：" + formatter.format(deptChangeScanInfo.getDeptChangeEffectiveDate()) + "。生效后请主动调整该人员的职务和岗位");
        } else {
            return AjaxResult.error("【科室调整失败】");
        }
    }

    /**
     * 输入用户id查科室信息
     *
     * @param userId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:getDeptInfoByUserId')")
    @GetMapping("/getDeptInfoByUserId/{userId}")
    public AjaxResult getDeptInfoByUserId(@PathVariable("userId") Long userId) {
        return AjaxResult.success(personScheduledService.getDeptInfoByUserId(userId));
    }

    /**
     * 调整薪级
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:insertSalaryChangeScanInfo')")
    @Log(title = "【人员调整】调整薪级", businessType = BusinessType.INSERT)
    @PostMapping("/insertSalaryChangeScanInfo")
    public AjaxResult insertSalaryChangeScanInfo(@RequestBody SalaryChangeScanInfo salaryChangeScanInfo) {
       return AjaxResult.success(personScheduledService.insertSalaryChangeScanInfo(salaryChangeScanInfo));
    }

    /**
     * 输入id查员工薪级信息
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:obtainSalaryInformation')")
    @GetMapping("/obtainSalaryInformation/{userId}")
    public AjaxResult obtainSalaryInformation(@PathVariable("userId") Long userId) {
        return AjaxResult.success(personScheduledService.obtainSalaryInformation(userId));
    }

    /**
     *获取薪级下拉列表
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:getSalarySelectList')")
    @GetMapping("/getSalarySelectList")
    public AjaxResult getSalarySelectList(){
        return AjaxResult.success(compensationSalarySettingService.selectCompensationSalarySettingAndChildren());
    }


    /**
     * 输入id查员工状态信息
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:obtainEmployeeStatusInformation')")
    @GetMapping("/obtainEmployeeStatusInformation/{userId}")
    public AjaxResult obtainEmployeeStatusInformation(@PathVariable("userId") Long userId) {
        return AjaxResult.success(personScheduledService.obtainEmployeeStatusInformation(userId));
    }

    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:insertEmployeeStatusChangeScanInfo')")
    @Log(title = "【人员调整】调整员工状态", businessType = BusinessType.INSERT)
    @PostMapping("/insertEmployeeStatusChangeScanInfo")
    public AjaxResult insertEmployeeStatusChangeScanInfo(@RequestBody EmployeeStatusScanInfo employeeStatusScanInfo) {
        int result = personScheduledService.insertEmployeeStatusChangeScanInfo(employeeStatusScanInfo);
        if (result > 0) {
            return AjaxResult.success("【调整员工状态成功】,生效时间为：" + formatter.format(employeeStatusScanInfo.getEmpStatusChangeEffectiveDate()));
        } else {
            return AjaxResult.error("【调整员工状态失败】");
        }
    }

    /**
     * 查询岗位扫描表列表
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:selectPositionChangeScanInfo')")
    @GetMapping("/selectPositionChangeScanInfo")
    public TableDataInfo selectPositionChangeScanInfo(PositionChangeScanInfo positionChangeScanInfo) {
        startPage();
        List<PositionChangeScanInfo> list = personScheduledService.selectPositionChangeScanInfoList(positionChangeScanInfo);
        return getDataTable(list);
    }

    /**
     * 查询职务扫描表列表
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:selectPostChangeScanInfo')")
    @GetMapping("/selectPostChangeScanInfo")
    public TableDataInfo selectPostChangeScanInfo(PostChangeScanInfo postChangeScanInfo) {
        startPage();
        List<PostChangeScanInfo> list = personScheduledService.selectPostChangeScanInfoList(postChangeScanInfo);
        return getDataTable(list);
    }

    /**
     * 查询科室扫描表列表
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:selectDeptChangeScanInfo')")
    @GetMapping("/selectDeptChangeScanInfo")
    public TableDataInfo selectDeptChangeScanInfo(DeptChangeScanInfo deptChangeScanInfo) {
        startPage();
        List<DeptChangeScanInfo> list = personScheduledService.selectDeptChangeScanInfoList(deptChangeScanInfo);
        return getDataTable(list);
    }

    /**
     * 查询薪资扫描表列表
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:selectDeptChangeScanInfo')")
    @GetMapping("/selectSalaryChangeScanInfo")
    public TableDataInfo selectDeptChangeScanInfo(SalaryChangeScanInfo salaryChangeScanInfo) {
        startPage();
        List<SalaryChangeScanInfo> list = personScheduledService.selectSalaryChangeScanInfoList(salaryChangeScanInfo);
        return getDataTable(list);
    }

    /**
     * 查询员工状态扫描表列表
     */
    @PreAuthorize("@ss.hasPermi('personnelMatters:schedule:selectEmployeeStatusChangeScanInfo')")
    @GetMapping("/selectEmployeeStatusChangeScanInfo")
    public TableDataInfo selectEmployeeStatusChangeScanInfo(EmployeeStatusScanInfo employeeStatusScanInfo) {
        startPage();
        List<EmployeeStatusScanInfo> list = personScheduledService.selectEmployeeStatusScanInfoList(employeeStatusScanInfo);
        return getDataTable(list);
    }
}
